package org.springframework.tx.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.*;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author ZouHaiBo
 * @version 1.0, 2021/8/11 16:32
 * @since JDK 1.8
 */
@Service
public class SpringTxTestServiceImpl implements SpringTxTestService
{

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	private SpringTxTestService springTxTestService;


	@Override
	public void add() {

		jdbcTemplate.execute("UPDATE `content_center_test`.`spring_tx_test` SET  `username`='2', `password`='3' WHERE (`id`='2');");

		springTxTestService.add2();
		springTxTestService.add3();

	}

	@Override
	@Transactional(propagation = Propagation.NESTED)
	public void add2() {
		jdbcTemplate.execute("INSERT INTO `content_center_test`.`spring_tx_test` (`id`, `username`, `password`) VALUES ('4', '4', '4');");
	}


	@Override
	@Transactional
	public void add3() {

		jdbcTemplate.execute("INSERT INTO `content_center_test`.`spring_tx_test` (`id`, `username`, `password`) VALUES ('5', '5', '5');");
		throw new RuntimeException();
	}



}
